package app.controller.wechat;

import java.io.IOException;
import java.util.Properties;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.scyf.bean.GlobalAccessToken;
import com.scyf.weixintool.WeiXinGlobalToken;
import com.scyf.weixintool.WeiXinMenuManage;

import app.utils.DataResponse;
import app.wechat.pojo.WeChat;
import net.sf.json.JSONObject;
@Controller
public class WechatMenuController {
	@Autowired
	@Qualifier("wechat")
	private WeChat weChat;


	@RequestMapping("/wechat/menu")
	public void weChatMenu(HttpServletResponse response) throws IOException{
		Properties properties=new Properties();
		properties.load(WechatMenuController.class.getResourceAsStream("/wechatmenu.properties"));
		String menu = properties.get("menu").toString();
		GlobalAccessToken globalAccessToken = WeiXinGlobalToken.getGlobalAccessToken(weChat.getAppId(), weChat.getAppSecret());
		JSONObject createMenu = WeiXinMenuManage.createMenu(globalAccessToken.getAccess_token(), menu);
		DataResponse.jsonResponse(response, createMenu.toString());
	}
}
